//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    inputShowed: false,
    inputVal: "",
    imgs: [
      "https://t11.baidu.com/it/u=266353081,834040762&fm=173&app=25&f=JPG?w=640&h=291&s=7395672A94C06CEA4007707B03008038",
      "https://t11.baidu.com/it/u=266353081,834040762&fm=173&app=25&f=JPG?w=640&h=291&s=7395672A94C06CEA4007707B03008038",
      "https://t11.baidu.com/it/u=266353081,834040762&fm=173&app=25&f=JPG?w=640&h=291&s=7395672A94C06CEA4007707B03008038",
      "https://t11.baidu.com/it/u=266353081,834040762&fm=173&app=25&f=JPG?w=640&h=291&s=7395672A94C06CEA4007707B03008038",
      "https://t11.baidu.com/it/u=266353081,834040762&fm=173&app=25&f=JPG?w=640&h=291&s=7395672A94C06CEA4007707B03008038",
    ]
  },
  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value
    });
  },
  toSearch(){
    // 进行搜索
    app.request('area.json', (data, msg)=>{
      console.log(data)
      console.log(msg)
    }, (msg) => {
      console.log(msg)
    });
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  selBtn(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: "/pages/list/list?cateId=" + id
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('onPullDownRefresh')
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('onReachBottom')
  },
})
